﻿/*
* jQuery.jUpload-0.0.1.js
* name:xiaojia 小嘉
* email:iatt@qq.com
* qq:273142650
* time:2012.7.27 10:15
*/

jQuery.extend({

	jUpload: {

		data: {

			url: null,

			thum: null,

			parent: null,

			object: []

		},

		bind: function () {

			var tag;

			var obj;

			for (var i = 0; i < this.data.object.length; i++) {

				obj = this.data.object[i];

				tag = obj.get(0).tagName.toLowerCase();

				switch (tag) {

					case 'input':

						obj.val(this.data.url);

						break;

					case 'img':

						obj.attr('src', this.data.url);

						break;

					default:

						obj.html(this.data.url);

						break;

				}

			}

			this.data.object = [];

		},

		parent: function (par) {

			if (par.frameElement != null) {

				if (par.frameElement.tagName.toLowerCase() != 'frame') {

					if (typeof par.jQuery != 'undefined') {

						if (typeof par.jQuery.jUpload != 'undefined') {

							this.data.parent = par;

						} else {

							this.parent(par.parent);

						}

					}

					this.parent(par.parent);

				} else {

					this.data.parent = par;

				}

			} else {

				this.data.parent = par;

			}

		},

		get: function () {

			this.parent(parent);

			var par = self;

			if (typeof this.data.parent.jQuery != 'undefined') {

				if (typeof this.data.parent.jQuery.jUpload != 'undefined') {

					par = this.data.parent;

				}

			}

			var width = par.window.innerWidth;

			var height = par.window.innerHeight;

			if (typeof width == 'undefined') {

				width = par.document.documentElement.clientWidth;

				height = par.document.documentElement.clientHeight;

			}

			for (var i = 0; i < arguments.length; i++) {

				par.jQuery.jUpload.data.object.push(jQuery(arguments[i]));

			}

			var id = 'jUploadTemplate_' + parseInt(Math.random() * (1000 + 9999));

			if (typeof __jUpload == 'undefined') {

				var __jUpload = {
				
					size: -1

				}

			}

			var box = par.jQuery.jLayer.layer({

				title: '我的文件夹',

				id: id,

				only: 1,

				restore: '',

				maximization: '',

				margin: 'auto auto',

				subject: '<iframe frameborder="0" width="100%" height="100%" src="/PublicClass/jPlugin/plugin/UploadFileTemplate/index.html#id=' + id + '&size=' + __jUpload.size + '"></iframe>',

				width: width * 0.8 + 'px',

				height: height * 0.8 + 'px'

			});

		}

	}

});